
    ### WinBUGS code for Hierarchical Poisson Model 

    
    ## a Varying-Intercept Model with Congress-Level Predictor  
    
    model {
    for (i in 1:N){
        # micro-level model
        Y[i] ~ dpois(mu.y[i])
        mu.y[i] <- (1 - u[i])*lambda[i]
        u[i] ~ dbern(pi[i])
        logit(pi[i]) <- delta[1] + delta[2]*W1[i] + delta[3]*W2[i] + delta[4]*W3[i]  # model for the binary process
        log(lambda[i])<-alpha[congress[i]] +         # model for the poisson process
                        beta[1]*X1[i] +
                        beta[2]*X2[i] + 
                        beta[3]*X3[i] +
                        beta[4]*X4[i] + 
                        beta[5]*X5[i] +
                        beta[6]*X6[i] + 
                        beta[7]*X7[i] +                           
                        beta[8]*X8[i]                            
        }
        # priors
        for (t in 1:n.beta){        
        beta[t] ~ dnorm(0, tau)
        }
        tau ~ dgamma(0.05, 0.01)
        itau <- 1/tau

        for (t in 1:n.delta){        
        delta[t] ~ dnorm(0, tau.delta)
        }
        tau.delta ~ dgamma(0.05, 0.01)
        itau.delta <- 1/tau.delta
              
        # macro-level model        

        for (j in 1:J){
        alpha[j] ~ dnorm(mu.alpha[j], tau.alpha)
        mu.alpha[j] <- gamma[1] + 
                       gamma[2]*Z1[j] + 
                       gamma[3]*Z2[j] + 
                       gamma[4]*Z3[j]             
        }

        # priors
        
        for (i in 1:n.gamma){
        gamma[i] ~ dnorm(0, 0.1)
        }
        
        tau.alpha ~ dgamma(0.05, 0.001)  
        itau.alpha <- 1/tau.alpha
       
    }


